#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int maxn = 100 + 50;
const int maxm = maxn * maxn;
const int INF = 1e8;

int dis[maxn][maxn];
int book[maxn];//book=0表示尚未扩展到的点
int n, m;

int Prim(int v = 1) {
    int tot = 0;
    int lowcost[maxn], closest[maxn], mincost;
    fill(lowcost, lowcost + n + 1, INF);
    for (int j = 1; j <= n; j++) {
        lowcost[j] = dis[v][j];
        closest[j] = v;
    }
    for (int i = 1; i <= n; i++) {
        if (i == v)continue;
        mincost = INF;
        int k = 1;
        for (int j = 1; j <= n; j++) {
            if (lowcost[j] != 0 && lowcost[j] < mincost) {
                mincost = lowcost[j];
                k = j;
            }
        }
        tot += mincost;
        cerr << "mincost=" << mincost << endl;
        lowcost[k] = 0;
        for (int j = 1; j <= n; j++) {
            if (dis[k][j] != 0 && dis[k][j] < lowcost[j]) {
                lowcost[j] = dis[k][j];
                closest[j] = k;
            }
        }
    }
    return tot;

}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ifstream fin("J.in");
    if (fin.good()) cin.rdbuf(fin.rdbuf());
    cin >> n;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            cin >> dis[i][j];
            if (dis[i][j] == 0 && i != j) {
                dis[i][j] = INF;
            }
        }

    cout << Prim();

    return 0;
}